# 29. 查找接口成功率最优时间段

29 29-1

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

const lines = [];
rl.on('line', (line) => {
    const average = parseInt(line);
    rl.on('line', (line) => {
        const rates = line.split(' ').map(Number);
        const arrayLength = rates.length;
        const sum = new Array(arrayLength);
        sum[0] = rates[0];
        for(let i=1; i<arraylength; i++) {
            sum[i] = sum[i-1] + rates[i]
        }
        let valid = [];
        let maxLength = 0;
        for(let start=0; start<arrayLength; start++) {
            for(let end=start; end<arrayLength; end++) {
                const n = start===0 ? sum[end]:sum[end] - sum[start-1];
                const length = end - start + 1;
                const loss = length * average;
                if (n <= loss) {
                    if (length > maxLength) {
                        valid = [];
                        valid.push([start, end]);
                        maxLength = length;
                    } else if(length === maxLength) {
                        valid.push([start, end]);
                    }
                }
            }
        }

        if(valid.length === 0) {
            console.log('NULL');
        } else {
            valid.sort((a,b) => a[0] - b[0]);
            console.log(valid.map(s => s.join('-')).join(' '));
        }
    });
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44